import Vue, { DirectiveOptions } from 'vue'

import 'normalize.css'
import ElementUI from 'element-ui'
import SvgIcon from 'vue-svgicon'

import '@/styles/element-variables.scss'
import '@/styles/index.scss'

import App from '@/App.vue'
import store from '@/store' // vuex
import { AppModule } from '@/store/modules/app'
import router from '@/router' // 路由
import i18n from '@/lang'
import '@/icons/components'
import '@/permission' // 权限管理
import '@/utils/error-log'
import '@/pwa/register-service-worker'
import * as directives from '@/directives' // 自定义指令
import * as filters from '@/filters' // 过滤器
import components from '@/components/index' // 全局组件
import print from 'vue-print-nb'
Vue.directive('print', print)

Vue.use(ElementUI, {
  size: AppModule.size, // 设置默认尺寸
  i18n: (key: string, value: string) => i18n.t(key, value)
})

Vue.use(SvgIcon, {
  tagName: 'svg-icon',
  defaultWidth: '1em',
  defaultHeight: '1em'
})

Vue.use(components)

// 注册全局指令
Object.keys(directives).forEach(key =>
  Vue.directive(key, (directives as { [key: string]: DirectiveOptions })[key])
)

// 注册全局过滤器
Object.keys(filters).forEach(key =>
  Vue.filter(key, (filters as { [key: string]: Function })[key])
)

Vue.config.productionTip = false

new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount('#app')
